// pages/myset/index.js
const app = getApp() // 引入app
import _request from '../../utils/request.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    checked: true,
    imgUrl: app.globalData.imgUrl, //全局img路径
    menu: [{
        name: "微信账号",
        url: "../setpassword/index",
        img: "https://kjyiyue.oss-cn-shenzhen.aliyuncs.com/images/set4.png",
        text: "未绑定",
        text1: "已绑定",
        text2: "审核中",
      },
      {
        name: "实名认证",
        url: "../myset/realname/index",
        img: "https://kjyiyue.oss-cn-shenzhen.aliyuncs.com/images/set5.png",
        text: "未实名",
        text1: "已实名"
      },
      {
        name: "提现账户管理",
        url: "../setpassword/index",
        img: "https://kjyiyue.oss-cn-shenzhen.aliyuncs.com/images/set6.png",
        text: ""
      },
      {
        name: "支付密码",
        url: "../payfail/index",
        img: "https://kjyiyue.oss-cn-shenzhen.aliyuncs.com/images/set7.png",
        text: ""
      },
      {
        name: "清理缓存",
        url: "../setpassword/index",
        img: "https://kjyiyue.oss-cn-shenzhen.aliyuncs.com/images/set8.png",
        text: "500MB"
      },
      {
        name: "分享意约",
        url: "",
        img: "https://kjyiyue.oss-cn-shenzhen.aliyuncs.com/images/set9.png",
        text: "",
        incident: 'onClick',
        userStatus: ''
      }
    ],
    showShare: false,
    options: [{
        name: '微信',
        icon: 'wechat',
        openType: 'share'
      },
      {
        name: '微博',
        icon: 'weibo'
      },
      {
        name: '复制链接',
        icon: 'link'
      },
      {
        name: '分享海报',
        icon: 'poster'
      },
      {
        name: '二维码',
        icon: 'qrcode'
      },
    ],
    findObj: null,
    mobile: ''
  },

  // 分享操作
  onClick(event) {
    this.setData({
      showShare: true
    });
  },

  onClose() {
    this.setData({
      showShare: false
    });
  },

  onSelect(event) {
    Toast(event.detail.name);
    this.onClose();
  },

  // 需要手动对 checked 状态进行更新
  onChange({
    detail
  }) {
    this.setData({
      checked: detail
    });
  },

  // 退出登录
  onOut() {
    _request.get('/storeUser/logout', {
    }).then((res) => {
      wx.clearStorage()
      // wx.navigateTo({
      //   url: '/pages/login/index',
      // })
    }).catch((error) => {
      console.log(error, 'error');
    })
  },

  // onIn
  onIn(){
    wx.navigateTo({
      url: '/pages/login/index',
    })
  },
  
  formatPhone(phone) {
    return phone.substr(0, 3) + '****' + phone.substr(7, 11);
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // 账户信息
    _request.get('/settings/accountSafe/find', {
      userId: wx.getStorageSync('userid')
    }).then((res) => {
      this.setData({
        findObj: res.data.data,
        mobile: this.formatPhone(res.data.data.mobile)
      })
    }).catch((error) => {
      console.log(error, 'error');
    })

    // // 实名状态
    // _request.get('/userAuthApply/getApplyStatus', {
    //   userId: wx.getStorageSync('userid')
    // }).then((res) => {
    //   this.setData({
    //     userStatus: res.data.data.applyStatus
    //   })
    // }).catch((error) => {
    //   console.log(error, 'error');
    // })

    // 是否设置密码
    _request.get('/settings/initPayWord', {
      userId: wx.getStorageSync('userid'),
    }).then((res) => {
      if (res.data.message == '支付密码还未设置' && res.data.data == 0) {
        this.setData({
          bool :false
        })
      }else{
        this.setData({
          bool :true
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})